import mongoose, { Schema, Document } from 'mongoose'

export interface ILessonDocument extends Document {
    order: number //顺序
    title: string //标题
    video: string // 视频
    poster: string // 海报
    url: string
    price: string
    category: string
    _doc: ILessonDocument
}

const LessonSchema: Schema<ILessonDocument> = new Schema({
    order: Number,
    title: String,
    video: String,
    url: String,
    price: String,
    category: String
}, {
    timestamps: true, toJSON: {
        transform: function (_doc: any, result: any) {
            result.id = result._id
            delete result._id
            delete result.__v
            return result
        }
    }
})

export const Lesson = mongoose.model<ILessonDocument>('Lesson', LessonSchema)